using System;
namespace ServiceStack
{
	public static class RestrictExtensions
	{
		public static RequestAttributes ToAllowedFlagsSet(this RequestAttributes restrictTo)
		{
			if (restrictTo == RequestAttributes.Any)
			{
				return RequestAttributes.Any;
			}
			RequestAttributes requestAttributes = RequestAttributes.None;
			if (!RestrictExtensions.HasAnyRestrictionsOf(restrictTo, RequestAttributes.AnyNetworkAccessType))
			{
				requestAttributes |= RequestAttributes.AnyNetworkAccessType;
			}
			else
			{
				requestAttributes |= (restrictTo & RequestAttributes.AnyNetworkAccessType);
			}
			if (!RestrictExtensions.HasAnyRestrictionsOf(restrictTo, RequestAttributes.AnySecurityMode))
			{
				requestAttributes |= RequestAttributes.AnySecurityMode;
			}
			else
			{
				requestAttributes |= (restrictTo & RequestAttributes.AnySecurityMode);
			}
			if (!RestrictExtensions.HasAnyRestrictionsOf(restrictTo, RequestAttributes.AnyHttpMethod))
			{
				requestAttributes |= RequestAttributes.AnyHttpMethod;
			}
			else
			{
				requestAttributes |= (restrictTo & RequestAttributes.AnyHttpMethod);
			}
			if (!RestrictExtensions.HasAnyRestrictionsOf(restrictTo, RequestAttributes.AnyCallStyle))
			{
				requestAttributes |= RequestAttributes.AnyCallStyle;
			}
			else
			{
				requestAttributes |= (restrictTo & RequestAttributes.AnyCallStyle);
			}
			if (!RestrictExtensions.HasAnyRestrictionsOf(restrictTo, RequestAttributes.AnyFormat))
			{
				requestAttributes |= RequestAttributes.AnyFormat;
			}
			else
			{
				requestAttributes |= (restrictTo & RequestAttributes.AnyFormat);
			}
			if (!RestrictExtensions.HasAnyRestrictionsOf(restrictTo, RequestAttributes.AnyEndpoint))
			{
				requestAttributes |= RequestAttributes.AnyEndpoint;
			}
			else
			{
				requestAttributes |= (restrictTo & RequestAttributes.AnyEndpoint);
			}
			return requestAttributes;
		}
		public static bool HasAnyRestrictionsOf(RequestAttributes allRestrictions, RequestAttributes restrictions)
		{
			return (allRestrictions & restrictions) > RequestAttributes.None;
		}
	}
}
